<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2024/11/20
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<script type="application/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="application/javascript">
    function register() {
        let username = document.getElementById("username").value;
        let password = document.getElementById("password").value;

        //create json
        let promts = {"username":username,"password": password}
        //build json object
        let jsonObj = JSON.stringify(promts);

        //post url
        let url = "${pageContext.request.contextPath}/stu/insertStu.do";
        $.ajax({
            type: 'post',
            url: url,
            contentType: 'application/json;charset=utf-8',
            data: jsonObj,
            success: (res=>{
                console.log("res >>>", res);
                alert(res.username +  ":" + res.password)
            }),
            error: function (error) {
                console.log("error >>>", error);
            },
        })
    }
</script>
<html>
<head>
    <title>用户注册</title>
</head>
<body>
用户名： <input type="text" name="username" id="username"> <br>
密码： <input type="text" name="password" id="password"> <br>
<input type="button" value="注册" onclick="register()">
</body>
</html>
